﻿using Model;
using Smobiler.Core;
using Smobiler.Core.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using FubiManger.Controls;
using Newtonsoft.Json;

namespace FubiManger.UI
{
    partial class FrimForm : Smobiler.Core.Controls.MobileForm
    {
        public FrimForm() : base()
        {
            //This call is required by the SmobilerForm.
            InitializeComponent();
        }
        /// <summary>
        /// 商品集合
        /// </summary>
        public List<Gdpro> gdlsit { get; set; }
        /// <summary>
        /// 订单金额
        /// </summary>
        public double money { get; set; }
        /// <summary>
        /// 支付金额
        /// </summary>
        private double paymoney { get; set; }
        /// <summary>
        /// 优惠券金额
        /// </summary>
        private double discount_price = 0;
        /// <summary>
        /// 积分
        /// </summary>
        private int integral = 0;
        /// <summary>
        /// 用户
        /// </summary>
        public ms_user user { get; set; }
        /// <summary>
        /// 商家ID
        /// </summary>
        public string merchantid { get; set; }
        /// <summary>
        /// 桌号
        /// </summary>
        public string disksn { get; set; }
        /// <summary>
        /// 用户ID
        /// </summary>
        public string adminid { get; set; }
        /// <summary>
        /// 1到店2物流
        /// </summary>
        public string u_sage { get; set; }

        private void panclose_Press(object sender, EventArgs e)
        {
            this.Close();
        }
        /// <summary>
        /// 确认订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnfrim_Press(object sender, EventArgs e)
        {
            ms_order ord = new ms_order();
            ord.order_sn = DateTime.Now.ToString("yyyyMMddHHmmssms");//订单号
            ord.pay_sn = DateTime.Now.ToString("yyyyMMddHHmmssms");//支付单号
            ord.pay_price = paymoney.ToString();//支付金额
            ord.discount_price = "0.00";//优惠金额
            ord.order_price = money.ToString();//订单金额
            ord.integral = integral.ToString();//积分
            ord.integral_grant = "2";//未发放积分
            ord.pay_type = "4";//线下支付
            ord.status = "1";//未支付
            ord.orderdisksn = disksn;//桌号
            ord.codestatus = "2";//无需核销
            ord.user_id = "0";
            ord.user_tel = user.username;//手机号
            ord.orderremark = txtremark.Text;//订单备注
            ord.add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//下单时间
            ord.merchant_id = merchantid;//商家ID
            ord.goods_info = JsonConvert.SerializeObject(gdlsit);
            ord.is_online = "2";//线下订单
            ord.ordertype = "1";//普通订单
            ord.u_sage = u_sage;//到店或物流
            ord.sales_id = adminid;//销售员ID
            orderDal.Addorder(ord);//创建订单
            OrdinfoForm frm = new OrdinfoForm();
            frm.ordsn = ord.order_sn;//订单号
            this.Form.Show(frm, true, (obj, args) => { this.Close(); });

        }

        private void FrimForm_Load(object sender, EventArgs e)
        {
            panpros.Height = gdlsit.Count * 50;
            panpro.Height = panpros.Height + 60 + 36;
            txtremark.Location = new System.Drawing.Point(10, panpros.Height + 30);
            for (int i = 0; i < gdlsit.Count; i++)
            {
                Productcountcontrol con = new Productcountcontrol();
                con.cover = gdlsit[i].proimg;//封面
                con.procount = "x " + gdlsit[i].count.ToString();//数量
                con.proname = gdlsit[i].proname;//名称
                panpros.Controls.Add(con);
            }
            paymoney = money - discount_price;//
            lblmoney.Text = "￥" + paymoney.ToString() + "  ";
            // lblbmoney.Text = "￥" + money.ToString();//优惠前金额
            //int amount = integral_ruleDal.Querybymerchantid(merchantid);//查商户积分规则         
            //if (amount > 0)
            //{
            //    double minter = Math.Floor(paymoney / amount);
            //    integral = Convert.ToInt32(minter);
            //    lblintegral.Text = integral + "金赑";
            //}
            //else
            //{
            //    integral = 0;
            //    lblintegral.Text = integral + "金赑";
            //}
        }
    }
}